let tree = {
    a:1,
    b:{
        c:2,
        d:3,
        e:{
            f:4,
            g:5
        }
    }
}
// 格式
// a = 1,b.c = 2,b.d = 3...
let obj = {}, arr = []
function treeFlat(tree) {
   
    for(let i in tree) {
        arr.push(i)
        let flag = arr.join('.')
        console.log(arr);
        if(tree.hasOwnProperty(i)) {
            obj[flag] = tree[i] instanceof Object ? treeFlat(tree[i]) : tree[i]
        }
        arr.pop()
    }
}
treeFlat(tree)
console.log(obj);


let narr = [1,2,[1,2,[1,2,[1,[2,[3]]]]]], Arr = []
function newflat(arr) {
    for(let item of arr) {
        if(item instanceof Array) {
            newflat(item)
        }
        else {
            Arr.push(item)
        }
    }
}
newflat(narr)
console.log(Arr);